<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="名称" prop="houseName">
        <el-input
            v-model="queryParams.houseName"
            placeholder="请输入名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="租金" prop="rent">
        <el-input
            v-model="queryParams.rent"
            placeholder="请输入租金"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="address">
        <el-input
            v-model="queryParams.address"
            placeholder="请输入详细地址"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="houseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房源id" align="center" prop="id" />
      <el-table-column label="名称" align="center" prop="houseName" />
      <el-table-column label="楼盘id" align="center" prop="housingId" />
      <!--      <el-table-column label="租赁方式" align="center" prop="rentMethod" />-->
      <el-table-column label="房源状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.houseStatus==0">未出租</span>
          <span v-if="scope.row.houseStatus==1">已出租</span>
        </template>
      </el-table-column>
      <el-table-column label="房产面积" align="center" prop="coveredArea" />
      <el-table-column label="租金" align="center" prop="rent" />
      <!--      <el-table-column label="看房时间" align="center" prop="time" />-->
      <el-table-column label="房源创建时间" align="center" prop="created" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.created }}</span>
        </template>
      </el-table-column>
      <el-table-column label="详细地址" align="center" prop="address" />
      <!-- <el-table-column label="房源标签类型" align="center" prop="labelType" />
     <el-table-column label="房东id" align="center" prop="landlordId" />
      <el-table-column label="发布状态  0已发布  1未发布" align="center" prop="publishStatus" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
export default {
  //房源列表
  name: "HouseView",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房源表格数据
      houseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        houseName: null,
        housingId: null,
        rentMethod: null,
        houseStatus: null,
        buildingNum: null,
        buildingUnit: null,
        buildingFloorNum: null,
        houseType: null,
        decoration: null,
        floor: null,
        rent: null,
        paymentMethod: null,
        coveredArea: null,
        orientation: null,
        contact: null,
        mobile: null,
        time: null,
        created: null,
        updated: null,
        userId: null,
        pid: null,
        cid: null,
        did: null,
        address: null,
        labelType: null,
        landlordId: null,
        houseDesc: null,
        publishStatus: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房源列表 */
    getList() {
      this.loading = true;
      this.axios.get("http://localhost:8080/house/house/list",{
        params:{
          pageNum:this.queryParams.pageNum,
          pageSize:this.queryParams.pageSize,
          houseName:this.queryParams.houseName,
          rent:this.queryParams.rent,
          address:this.queryParams.address,

        }
      }).then(response => {
        console.log(response.data)
        this.houseList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        proportion: null,
        direction: null,
        rental: null,
        privateFacility: null,
        publicFacility: null,
        premisesId: null,
        subwayId: null,
        subwayStation: null
      };
      if (this.$refs.queryForm) {
        this.$refs.queryForm.resetFields();
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      if (this.$refs.queryForm) {
        this.$refs.queryForm.resetFields();
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    }
  }
}
</script>

<style scoped>

</style>
